//
//  UIView+TYZAdd.m
//  DriveSchoolCoach
//
//  Created by TangBin on 2019/8/9.
//  Copyright © 2019 TangBin. All rights reserved.
//

#import "UIView+TYZAdd.h"

@implementation UIView (TYZAdd)

+ (UIViewAnimationOptions)animationOptionsForCurve:(UIViewAnimationCurve)curve
{
    switch (curve) {
        case UIViewAnimationCurveEaseInOut:
            return UIViewAnimationOptionCurveEaseInOut;
            break;
        case UIViewAnimationCurveEaseIn:
            return UIViewAnimationOptionCurveEaseIn;
            break;
        case UIViewAnimationCurveEaseOut:
            return UIViewAnimationOptionCurveEaseOut;
            break;
        case UIViewAnimationCurveLinear:
            return UIViewAnimationOptionCurveLinear;
            break;
    }
    
    return kNilOptions;
}

- (void)keyBoardsWillShow:(NSNotification *)note animations:(void (^)(void))animations completion:(void (^)(BOOL, CGRect))completion
{
    // 获取用户信息
    NSDictionary *userInfo = [NSDictionary dictionaryWithDictionary:note.userInfo];
    // 获取键盘高度
    CGRect keyBoardBounds  = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    //CGFloat keyBoardHeight = keyBoardBounds.size.height;
    // 获取键盘动画时间
    CGFloat animationTime  = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
    
    if (animationTime > 0)
    {
        [UIView animateWithDuration:animationTime animations:animations completion:^(BOOL finished) {
            if (completion)
            {
                completion(finished, keyBoardBounds);
            }
        }];
    }
    else
    {
        animations();
    }
}


- (void)keyBoardsWillHide:(NSNotification *)note animations:(void (^)(void))animations completion:(void (^)(BOOL))completion
{
    // 获取用户信息
    NSDictionary *userInfo = [NSDictionary dictionaryWithDictionary:note.userInfo];
    // 获取键盘动画时间
    CGFloat animationTime  = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
    
    if (animationTime > 0)
    {
        [UIView animateWithDuration:animationTime animations:animations completion:^(BOOL finished) {
            if (completion)
            {
                completion(finished);
            }
        }];
    }
    else
    {
        animations();
    }
}


//刘海高度
- (CGFloat)bangsScreenSize
{
    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
    {
        return 0;
    }
    CGSize size = [UIScreen mainScreen].bounds.size;
    NSInteger notchValue = size.width / size.height * 100;
    if (216 == notchValue || 46 == notchValue)
    {
        return 34;
    }
    return 0;
}

@end
